layui.use(['layer', 'form'], function(){
    var layer = layui.layer
        ,form = layui.form;
    form.on('select(myselect)', function(data) {
        var areaId = data.value;
        $.ajax({
            url: "app/categorize",
            data: {parentId: areaId},
            type: "POST",
            dataType: "json",
            success: function (data) {
                $("#categoryLevel2").html("");
                var option = "<option value=''>--请选择--</option>";

                for (var i = 0; i < data.length; i++) {
                    option += "<option value='" + data[i].id + "'>" + data[i].categoryName + "</option>";
                }
                $("#categoryLevel2").html(option);
                form.render('select');
            }


        });

    });
    form.on('select(myselect2)', function(data) {
        var areaId = data.value;
        alert(areaId);
        $.ajax({
            url: "app/categorize",
            data: {parentId: areaId},
            type: "POST",
            dataType: "json",
            success: function (data) {
                $("#categoryLevel3").html("");
                var option = "<option value=''>--请选择--</option>";

                for (var i = 0; i < data.length; i++) {
                    option += "<option value='" + data[i].id + "'>" + data[i].categoryName + "</option>";
                }
                $("#categoryLevel3").html(option);
                form.render('select');
            }


        });

    });
})


function selList() {
    var softwareName=$("#softwareName").val();
    var pageIndex=$("#pageIndex").val();
    var status=$("#status").val();
    var flatformId=$("#flatformId").val();
    var categoryLevel1=$("#categoryLevel1").val();
    var categoryLevel2=$("#categoryLevel2").val();
    var categoryLevel3=$("#categoryLevel3").val();

    $.ajax({
        url: "app/listss",
        data: {softwareName: softwareName,status:status,flatformId:flatformId,
               categoryLevel1 :categoryLevel1,categoryLevel2:categoryLevel2,
               categoryLevel3:categoryLevel3,pageIndex:pageIndex},
        type: "POST",
        dataType: "json",
        success: function (data) {
            $("#indexs").siblings().remove();
            var  $html;
            alert(data.appList);
            if(data.appList!=null &&data.appList!=''){
            for(var i=0;i<data.appList.length;i++){
                var $opera;

                    $opera="<select onchange='operation(this," + data.appList[i].id + ")'" + " style='background-color: black;color: white;padding-bottom: 3px'>"
                        + "<option value=''>点击操作</option>"
                        + "<option value=1>新增版本</option>"
                        + "<option value=2>修改版本</option>"
                        + "<option value=3>下架</option>"
                        + "<option value=4>修改</option>"
                        + "<option value=5>查看</option>"
                        + "<option value=6>删除</option>"
                        + "</select>"


                $html="<tr><td>"+data.appList[i].softwareName+"</td>"
                    +"<td>"+data.appList[i].aPKName+"</td>"
                    +"<td>"+data.appList[i].softwareSize+"</td>"
                    +"<td>"+data.appList[i].flatformName+"</td>"
                    +"<td>"+data.appList[i].categoryLevel1Name+"->"
                    +data.appList[i].categoryLevel2Name+"->"
                    +data.appList[i].categoryLevel3Name +"</td>"
                    +"<td>"+data.appList[i].statusName+"</td>"
                    +"<td>"+data.appList[i].downloads+"</td>"
                    +"<td>"+data.appList[i].versionNo+"</td>"
                    +"<td>"+$opera+"</td></tr>";

                $("#index").append($html);
            }
            }else{
                $html="<span>对不起，没有找到与之匹配的值</span>";
                $("#index").append($html);
            }

        }
    })
}